import { title } from "process"
import { mongo } from "../mogoConfig"

const run = async () => {

    const movieTB = mongo.db("sample_mflix").collection("movies")

    let cursor = movieTB.find({
        $text: { $search: "trek" }
    }).project({ _id: 0, title: 1 })
    console.log("全文搜索查询1------------------------------")
    for await (const item of cursor) {
        console.log(JSON.stringify(item))
    }


    cursor = movieTB.find({
        $text: { $search: '"star trek"' }
    }).project({ _id: 0, title: 1 })
    console.log("全文搜索查询2------------------------------")
    for await (const item of cursor) {
        console.log(JSON.stringify(item))
    }


    cursor = movieTB.find({
        $text: { $search: '"star trek" -"into darkness"' }
    }).project({ _id: 0, title: 1 })
    console.log("全文搜索查询3------------------------------")
    for await (const item of cursor) {
        console.log(JSON.stringify(item))
    }


    cursor = movieTB.find({
        $text: { $search: '"star trek" -"into darkness"' }
    }).project({ _id: 0, title: 1, score: { $meta: "textScore" } }).sort({ score: { $meta: "textScore" } })
    console.log("全文搜索查询4------------------------------")
    for await (const item of cursor) {
        console.log(JSON.stringify(item))
    }


}


run()
    .catch(error => {
        console.log(error)
    })
    .finally(() => {
        mongo.close()
        console.log("执行结束")
    })